// cd /projects/hsieh_project/proj_201809/code_1_data/
// qstata cw_ind_aux.do &

set linesize 255

clear all
cd /projects/

di "$S_TIME $S_DATE"

global rev_date: display %tdYYNNDD date("$S_DATE", "DMY")
di "${rev_date}"

global dir_proj "/projects/hsieh_project/proj_201809/"

global dir_do "${dir_proj}/202011_main/"
global dir_data "${dir_proj}/data/"

//==============================================================================

use "/projects/data_commons/cw/cw_ind_fk_imp", clear

tostring fk_naics, gen(fk_naics2)
replace fk_naics2 = substr(fk_naics2,1,2)
bysort ch_ind: egen n_aux = total(fk_naics2=="54" | fk_naics2 == "55")
keep if n_aux > 0
bysort ch_ind: gen s_aux = n_aux / _N

save ${dir_data}/cw_ind_fk_aux, replace
saveold ${dir_data}/cw_ind_fk_aux_v12, replace v(12)

//------------------------------------------------------------------------------
// Confirm that fk_naics12 does not cause any trouble

use "/projects/data_commons/cw/cw_ind_fk_imp_fk12", clear

tostring fk_naics, gen(fk_naics2)
replace fk_naics2 = substr(fk_naics2,1,2)
bysort ch_ind: egen n_aux = total(fk_naics2=="54" | fk_naics2 == "55")
keep if n_aux > 0
bysort ch_ind: gen s_aux = n_aux / _N

rename ch_ind ch_ind_a
rename n_aux n_aux_a
rename s_aux s_aux_a

merge 1:1 fk_naics using ${dir_data}/cw_ind_fk_aux
list if ch_ind_a != ch_ind
 
di "Ended at $S_DATE $S_TIME"
// End of do file
